package util.resource;

import java.io.File;
import java.util.ArrayList;

/**
 * Utility class for loading a bunch of different files from a directory.
 * @author Logan
 */
public class FileLocator
{
	private FileLocator()
	{
		//Can't instantiate a FileLocator Object
	}
	
	/**
	 * Gets a simple list of all the files in a directory to load later on.
	 * @param baseDirectory - directory to load files from.
	 * @param extension - extension of files to load.
	 * @param deepSearch - if true, also check all subfolders for files.
	 * @return a list of all files found that satisfy said criteria
	 */
	public static ArrayList<File> getFileLocations(String baseDirectory,String extension,boolean deepSearch)
	{
		//Returns an ArrayList containing strings of valid files in the baseDirectory with
		//the file extension extension. If deepSearch is true, then it will search all sub-directories
		//of baseDirectory.
		
		ArrayList<File> fileList=new ArrayList<File>();
		
		File base=new File(baseDirectory);
		File[] files=base.listFiles();
		for(int i=0;i<files.length;i++)
		{
			if(files[i].isFile())
			{
				if(files[i].getName().endsWith(extension))
					fileList.add(files[i]);
			}
			else if(files[i].isDirectory() && deepSearch)
				fileList.addAll(getFileLocations(files[i].getAbsolutePath(),extension,true));
		}
		
		return fileList;
	}
}
